package 尚硅谷;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhangmin
 * @create 2022-03-22 16:23
 */
public class CASDemo {

    public static void main(String[] args) {
        AtomicInteger atomicInteger=new AtomicInteger(5);

        System.out.println(atomicInteger.compareAndSet(5,2022)+"\t current data:"+atomicInteger.get()); //比较是否为期望值，若是，则改变值
        System.out.println(atomicInteger.compareAndSet(5,2021)+"\t current data:"+atomicInteger.get()); //此时比较结果为false
    }
}
